@extends('layout.main')
@section('css')
<!-- <link rel="stylesheet" href="/assets/js/plugins/jstree/themes/default/style.min.css" /> -->
<link rel="stylesheet" href="/assets/js/plugins/blueimp/css/style.css">
<link rel="stylesheet" href="/assets/css/plugins/chosen/chosen.css">
<link href="/assets/css/style.css" rel="stylesheet">
<link rel="stylesheet" href="/assets/js/plugins/blueimp/css/jquery.fileupload.css">
<link rel="stylesheet" href="/assets/js/plugins/select2/css/select2.min.css">
<!-- <link rel="stylesheet" href="/assets/js/plugins/tagsinput/bootstrap-tagsinput.css">
<link rel="stylesheet" href="/assets/js/plugins/tagsinput/app.css"> -->
<link href="/assets/js/plugins/summernote/dist/summernote.css" rel="stylesheet">
@endsection
@section('content')
<div class="row">
    <div class="col-lg-12">
        <div class="ibox float-e-margins">
            <div>
                <form id="form" method="post" class="form-horizontal" action="/ios/edit">
                <input type="hidden" name="id" value="{{$info->id}}">
                    <div class="form-group"><label class="col-sm-2 control-label">标题</label>
                        <div class="col-sm-10"><input type="text" name="title" class="form-control" value="{{$info->title}}"></div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>
                    
                    <div class="form-group"><label class="col-sm-2 control-label">精简标题</label>
                        <div class="col-sm-10"><input type="text" name="subtitle" class="form-control" value="{{$info->subtitle}}"></div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    
                    <div class="form-group"><label class="col-sm-2 control-label">首字母</label>
                        <div class="col-sm-10">
                            <input type="text" name="indexf" value="{{$info->indexf}}" class="form-control" maxlength="1">
                        </div>
                    </div>

                    <!--  <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">标签（搜索关键字）</label>
                        <div class="col-sm-10">
                            <input type="text" name="tagkey" value="{{$info->tagkey}}" class="form-control">
                            <span class="help-block m-b-none">以英文逗号","隔开</span>
                        </div>
                    </div> -->
                    
                     <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">标签关键字</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="tag" name="tag" multiple="multiple">
                            @forelse($tags as $item)
                            <option value="{{$item->id}}" selected="selected">{{$item->name}}</option>
                            @empty
                            @endforelse
                            </select>
                        </div>
                        <input type="hidden" id="htag" name="htag" />
                    </div>

                    <div class="hr-line-dashed"></div>
                    
                     <div class="form-group"><label class="col-sm-2 control-label">分类</label>
                        <div class="col-sm-10">
                            <div class="col-sm-6">
                            <select class="form-control" id="ptype_id" name="ptype_id" onchange="changetype(this.value)">
                            <option value="">请选择</option>
                                @foreach($ptypelist as $item)
                                    <option value="{{$item->id}}" @if ($info->ptype_id==$item->id) selected="selected" @endif>{{$item->name}}</option>
                                @endforeach
                            </select>
                            </div>
                            <div class="col-sm-6">
                            <select class="form-control" id="type_id" name="type_id">
                                @foreach($typelist as $item)
                                    <option value="{{$item->id}}" @if ($info->type_id==$item->id) selected="selected" @endif>{{$item->name}}</option>
                                @endforeach
                            </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">专题类型</label>
                        <div class="col-sm-10">
                            <select class="form-control chosen-select" data-placeholder="请选择专题" multiple >
                                @foreach($topiclist as $item)
                                <option value="{{$item->id}}" @foreach($sstopiclist as $vitem) @if($vitem->topic_id==$item->id)
                                selected="selected" @endif @endforeach>{{$item->title}}({{$item->typename}})</option>
                                @endforeach
                            </select>
                        </div>
                        <input type="hidden" id="topictype" name="topictype" />
                    </div>

                    <div class="hr-line-dashed"></div>
                    
                    <div class="form-group"><label class="col-sm-2 control-label">上传图片</label>
                        <div class="col-sm-10">
                            <!-- The fileinput-button span is used to style the file input field as button -->
                            <span class="btn btn-success fileinput-button"> <i class="glyphicon glyphicon-plus"></i>
                                <span>选择文件</span>
                                <!-- The file input field used as target for the file upload widget -->
                                <input id="fileupload" type="file" name="file"></span>
                            <!-- The container for the uploaded files -->
                            <div id="files" class="files">
                                <div>
                                <img src="{{$info->image}}" width='100px' height='100px'/>
                                <input type='text' name='image' class='form-control' readonly='readonly' value="{{$info->image}}"/>
                                </div>
                            </div>
                            <!-- The global progress bar -->
                            <div id="progress" class="progress">
                                <div class="progress-bar progress-bar-success"></div>
                            </div>
                        </div>
                    </div>
                    
                   

                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">下载url：</label>
                        <div class="col-sm-10"><input type="text" name="downurl" class="form-control" value="{{$info->downurl}}"></div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">本地下载url：</label>
                        <div class="col-sm-10"><input type="text" name="locdownurl" class="form-control" value="{{$info->locdownurl}}"></div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">软件语言</label>
                        <div class="col-sm-10"><input type="text" name="lang" class="form-control" value="{{$info->lang}}"></div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">大小：</label>
                        <div class="col-sm-10"><input type="text" name="filesize" class="form-control" value="{{$info->filesize}}"></div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>
                    
                    <div class="form-group"><label class="col-sm-2 control-label">软件授权</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="authtype" name="authtype">
                                <option value="">全部</option>
                                <option value="1" @if($info->authtype==1) selected="selected" @endif>试用版</option>
                                <option value="2" @if($info->authtype==2) selected="selected" @endif>共享版</option>
                                <option value="3" @if($info->authtype==3) selected="selected" @endif>免费版</option>
                                <option value="4" @if($info->authtype==4) selected="selected" @endif>自由版</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">相关版本关键字</label>
                        <div class="col-sm-10"><input type="text" name="relkey" class="form-control" value="{{$info->relkey}}"></div>
                    </div>
                    
                   <!--  <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">标签</label>

                    <div class="col-sm-10"><input type="text" id="tagIn" name="tagIn" /></div>

                    </div> -->

                   

                    <div class="hr-line-dashed"></div>
                    
                    <div class="form-group"><label class="col-sm-2 control-label">描述</label>

                    <div class="col-sm-10">
                        <div id="editor">{!!$info->content!!}</div>
                         <input type="hidden" id="content" name="content"/>
                    </div>

                    </div>
                    
                     <div class="hr-line-dashed"></div>
                    
                    <div class="form-group"><label class="col-sm-2 control-label">上传软件截图</label>
                        <div class="col-sm-10">
                            <!-- The fileinput-button span is used to style the file input field as button -->
                            <span class="btn btn-success fileinput-button"> <i class="glyphicon glyphicon-plus"></i>
                                <span>选择文件</span>
                                <!-- The file input field used as target for the file upload widget -->
                                <input id="ssfileupload" type="file" name="files[]" multiple></span>
                            <!-- The container for the uploaded files -->
                            <div id="ssfiles" class="files">
                            @if(count($ssarr)>0)
                                @foreach($ssarr as $item)
                                <div class="form-group">
                                    <div class='col-lg-2'><img src="{{$item}}" width='100px' height='100px'/></div>
                                    <div class='col-lg-10'><input type='text' name='screenshot[]' class='form-control' readonly='readonly' value="{{$item}}"/><button type='button' class='btn btn-w-m btn-danger' onclick='removeimg(this)'>删除</button></div>
                                </div>
                                @endforeach
                            @endif
                            </div>
                            <!-- The global progress bar -->
                            <div id="ssprogress" class="progress">
                                <div class="progress-bar progress-bar-success"></div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">标签</label>
                        <div class="col-sm-10">
                            <input type="text" name="tags" class="form-control" value="{{$info->tags}}">
                            <span class="help-block m-b-none">以英文逗号","隔开</span>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">系统要求</label>
                        <div class="col-sm-10"><input type="text" name="platform" class="form-control" value="{{$info->platform}}"></div>
                    </div>
                    
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">版本</label>
                        <div class="col-sm-10"><input type="text" name="version" class="form-control" value="{{$info->version}}"></div>
                    </div>

                   <div class="hr-line-dashed"></div>
                    
                    <div class="form-group">
                        <label class="col-sm-2 control-label">排序</label>
                        <div class="col-sm-10">
                            <label class="checkbox-inline">
                                <input name="sort" type="checkbox" value="1" @if($info->sort==1) checked="checked" @endif>
                                推荐
                            </label>
                            <label class="checkbox-inline">
                                <input name="pre" type="checkbox" value="1" @if($info->pre==1) checked="checked" @endif>
                                必备
                            </label>
                            <label class="checkbox-inline">
                                <input name="comuse" type="checkbox" value="1" @if($info->comuse==1) checked="checked" @endif>
                                常用
                            </label>
                            <label class="checkbox-inline">
                                <input name="ishot" type="checkbox" value="1" @if($info->ishot==1) checked="checked" @endif>
                            热点                            
                            </label>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    
                    <div class="form-group"><label class="col-sm-2 control-label">评分</label>
                        <div class="col-sm-10">
                            <input type="text" name="score" class="form-control" onkeyup="this.value=value.replace(/[^\-?\d.]/g,'')" onafterpaste="this.value=value.replace(/[^\-?\d.]/g,'')" value="{{$info->score}}">
                            <span class="help-block m-b-none">请输入0-100分的评分</span>
                        </div>
                    </div>

                    @if($gadmin->role_id!=7)
                    <div class="hr-line-dashed"></div>

                    <div class="form-group"><label class="col-sm-2 control-label">状态</label>

                        <div class="col-sm-10">
                            <div>
                            <label><input type="radio" name="status_at" @if ($info->status_at==1) checked="checked" @endif value="1">启用</label>
                            <label><input type="radio" name="status_at" @if ($info->status_at==0) checked="checked" @endif value="0">禁用</label>
                            </div>
                        </div>
                    </div>
                   @endif
                    <div class="hr-line-dashed"></div>
                   {!! csrf_field() !!}
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-white" type="reset">取消</button>
                            <button class="btn btn-primary" type="submit">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection

@section('js')
<script src="/assets/js/plugins/chosen/chosen.jquery.js"></script>
<script src="/assets/js/plugins/blueimp/js/vendor/jquery.ui.widget.js"></script>
<script src="/assets/js/plugins/blueimp/js/jquery.iframe-transport.js"></script>
<script src="/assets/js/plugins/blueimp/js/jquery.fileupload.js"></script>
<script src="/assets/js/plugins/select2/js/select2.min.js"></script>
<script src="/assets/js/plugins/select2/js/i18n/zh-CN.js"></script>
<script src="/assets/js/plugins/summernote/dist/summernote.min.js"></script>
<script src="/assets/js/plugins/summernote/lang/summernote-zh-CN.js"></script>
<script type="text/javascript" src="/assets/js/plugins/tagsinput/bootstrap-tagsinput.min.js"></script>
<script type="text/javascript" src="/assets/js/plugins/tagsinput/typeahead.bundle.js"></script>
<script type="text/javascript">
function changetype(v){
    $.get('/ios/typelist', {data: v}, function(data) {
        var html='';
        for(item in data){
            html+='<option value="'+data[item].id+'">'+data[item].name+'</option>';
        }
        $('#type_id').html('<option value="">请选择</option>'+html);
    },'json')
}
function removeimg(ele){
    $(ele).parent().parent().remove();
}
$(function(){
    $('#tag').select2({
        language: "zh-CN",
        placeholder: "请选择关键字",
        allowClear: true,
        ajax: {
            url: '/tag/search',
            dataType: 'json',
            delay: 250,
            data: function (params) {
              return {
                q: params.term, // search term
                page: params.page
              };
            },
            processResults: function (data, params) {
              params.page = params.page || 1;
              return {
                results: data.items,
                pagination: {
                  more: (params.page * 30) < data.total_count
                }
              };
            },
            cache: true
        },
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 1,
        templateResult: formatRepo, // omitted for brevity, see the source of this page
        templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
    });
     var config = {
        '.chosen-select'           : {},
        '.chosen-select-deselect'  : {allow_single_deselect:true},
        '.chosen-select-no-single' : {disable_search_threshold:10},
        '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
        '.chosen-select-width'     : {width:"95%"}
        }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }
    // 图片上传
    'use strict';
    $('#fileupload').fileupload({
        url: '/ios/uploadimg',
        dataType: 'json',
        limitMultiFileUploads: 1,
        singleFileUploads: true,
        done: function(e, data) {
            $.each(data.result.file, function(index, file) {
                var tmpimg = "<img src='" + file.url + "' width='100px' height='100px'/>";
                var tmpinput = "<input type='text' name='image' class='form-control' readonly='readonly' value='" + file.url + "'/>";
                $('#files').html('<div>' + tmpimg + tmpinput + '</div>')
                    // $('<div style="margin-top:20px;"/>').html(tmpimg + tmpinput).appendTo('#files');
            });
        },
        progressall: function(e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .progress-bar').css('width',progress + '%');
        }
    }).prop('disabled', !$.support.fileInput)
    .parent().addClass($.support.fileInput ? undefined : 'disabled');

     // 截图上传
    'use strict';
    $('#ssfileupload').fileupload({
        url: '/windows/uploadss',
        dataType: 'json',
        singleFileUploads: false,
        done: function(e, data) {
            $.each(data.result.file, function(index, file) {
                var tmpimg = "<div class='col-lg-2'><img src='" + file.url + "' width='100px' height='100px'/></div>";
                var tmpinput = "<div class='col-lg-10'><input type='text' name='screenshot[]' class='form-control' readonly='readonly' value='" + file.url + "'/><button type='button' class='btn btn-w-m btn-danger' onclick='removeimg(this)'>删除</button></div>";
                $('#ssfiles').append('<div class="form-group">' + tmpimg + tmpinput + '</div>');
            });
        },
        progressall: function(e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#ssprogress .progress-bar').css('width',progress + '%');
        }
    }).prop('disabled', !$.support.fileInput)
    .parent().addClass($.support.fileInput ? undefined : 'disabled');

    $('#editor').summernote({
        height:300,
        lang: 'zh-CN',
        onImageUpload: function(files) {
            $.each(files, function (idx, file) {
                var data = new FormData();
                data.append("file", file);
                $.ajax({
                    data: data,
                    type: "POST",
                    dataType: "json",
                    url: "/ios/upload",
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function(v) {
                        $('#editor').summernote('insertImage', v.file[0].url);
                    }
                });
            })
       }
    });
    $("#form").validate({
        rules: {
            title: {
                required: true
            },
            ptype_id: {
                required: true
            },
            type_id: {
                required: true
            },
            authtype: {
                required: true
            },
            downurl: {
                required: true
            },
            indexf: {
                required: true
            }
        },
        messages: {
            title: "请填写标题",
            ptype_id: "请选择分类",
            type_id: "请选择分类",
            authtype: "请选择授权类型",
            indexf:"请填写首字母"
        }
    });
    $('#form').on('submit', function() {
        $('#topictype').val($(".chosen-select").val());
        $('#htag').val($("#tag").val());
        $('#content').val($('#editor').code());
    })
})

</script>
@endsection